#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：group-learn 
@File    ：pythonTips.py
@IDE     ：PyCharm 
@Author  ：lcy-tester
@Date    ：2023/11/7 15:29 
'''

"""
18个小技巧
"""
from typing import List, Dict


def actionInput():
    """
    处理多个用户输入
    :return:
    """
    n1, n2, n3 = input("enter a number").split()
    print(n1, n2, n3)


def actionCondition():
    """
    处理多个条件
    :return:
    """
    size = "lg"
    color = "blue"
    price = 50

    conditions = [
        size == 'lg',
        color == 'blue',
        price == 50

    ]
    if all(conditions):
        print("yes, I want to but the product")

    if any(conditions):
        print("yes, I want to but the product11111")


def judgeNumber(number: int):
    """
    判断奇偶数
    :param number:
    :return:
    """
    print('偶数' if int(number) % 2==0 else "奇数")


def transNumber(number1: int, number2: int):
    """
    交换变量
    :param number1:
    :param number2:
    :return:
    """
    a, b = number1, number2
    print(f"原始：a = {a},b = {b}")
    a, b = b, a
    print(f"交换：a = {a},b = {b}")


def judgeHwc(strNum: str):
    """
    判断回文
    :param strNum:
    :return:
    """
    print(f"原始字符串：{strNum}")
    # if strNum[::-1] == strNum:
    #     print(f"是：{strNum[::-1]}")
    # else:
    #     print(f"不是：{strNum[::-1]}")
    # print(strNum.find("cha"))
    if strNum.find(strNum[::-1]) == 0:
        print(f"是：{strNum[::-1]}")


def deleteEle(listNum: List[int]):
    """
    删除重复元素
    :param listNum:
    :return:
    """
    print(f"originList:{listNum}")
    uniqueLst = list(set(listNum))
    print(f"afterList:{uniqueLst}")
    ...


def queryMoreEle(listNum: List[int]):
    """
    重复最多的元素
    :param listNum:
    :return:
    """
    mostRepeatedItem = max(listNum, key=listNum.count)
    print(f"最多的元素：{mostRepeatedItem}")
    print()


def generateList():
    """
    列表推导式
    :return:
    """
    number = [1, 2, 3, 4, 5, 6, 7]
    event = [x for x in number if x % 2 == 0]
    print(event)

    cities = ['London', "Dublin", "Oslo"]

    def visit(city):
        print("welcome to " + city)

    for city in cities:
        visit(city)


def oIndex(lst: List):
    """
    获取元素处理下标
    :param lst:
    :return:
    """
    print(f"原始列表：{lst}")
    for index, item in enumerate(lst):
        print(index, item)


def joinStrings(lst: List):
    """
    拼接字符串
    :param lst:
    :return:
    """
    print(",".join(lst))


def concatDict(dic1: Dict, dic2: Dict):
    """
    合并字典
    :param dic1:
    :param dic2:
    :return:
    """
    print(f"原子典：\n{dic1}\n{dic2}")
    d3 = {**dic1, **dic2}
    print(d3)


def lstGeneratorDict(lst1: List[str], lst2: List):
    """
    两个列表合成一个字典
    :param lst1:
    :param lst2:
    :return:
    """
    print(f"原列表：\n{lst1}\n{lst2}")
    d3 = dict(zip(lst1, lst2))
    print(d3)


def dicToValueOrder(dic: Dict):
    """
    字典按照【value】排序
    :param dic:
    :return:
    """
    print(f"原字典：{dic}")
    sortedDic = dict(sorted(dic.items(), key=lambda item: item[1], reverse=True))  # 默认升序，reverse=True为降序
    print(sortedDic)


def reverseLst(lst: List):
    """
    反转列表
    :param lst:
    :return:
    """
    print(f"源列：{lst}")
    # 切片方式  创建新列表
    lst1 = lst[::-1]
    print(lst1)
    print(lst)
    # reverse方式 更改原始列表

    # print(list(reversed(lst)))


if __name__ == '__main__':
    # actionInput()
    # actionCondition()
    # judgeNumber(2)
    # transNumber(1, 2)
    # judgeHwc("cha")
    # deleteEle([1, 1, 2, 2, 3, 3])
    # queryMoreEle([1, 1, 1, 1, 2, 2, 2, 3])
    # generateList()
    # oIndex(['cs', 'sd', 'et'])
    # joinStrings(['cs', 'sd', 'et'])
    # concatDict({"v1": 22, "v2": 45}, {"v3": 11, "v4": 0})
    # lstGeneratorDict(["a", "b", "c"], [1, 2, 3])
    # dicToValueOrder({"v1": 80, "v2": 90, "v3": 60, })
    reverseLst(["1", 2, "3", 4])
    # print(sorted())
    ...
